<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <!--    <h:body>-->
    <ui:composition template="layout.xhtml">-->

        <ui:define name="corpo">
            <h:form id="buscar_form" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexImovel.xhtml')}" value="Imóvel" update="@form" immediate="true"/> >
                    <p:commandLink  value="Pesquisar Imóvel" update="@form" immediate="true"/>
                </div>
                <p:panel header="Pesquisar Imóvel">
                <p:messages id="msg"/>
                <f:validateBean disabled="true">
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Filtros"/></legend>

                        <fieldset class="ui-fieldset" >
                            <legend><h:outputLabel value="Dados Imóvel"/></legend>
                            <h:panelGrid columns="2" id="panelGridObjeto" style="width: 100%"
                                         styleClass="textAlignRight" columnClasses="textAlignRight">


                                <h:outputLabel value="Registro: "/> 
                                <p:inputMask value="#{managerBuscarImovel.imovel.registro}" 
                                             maxlength="11" mask="99999"/>

                                <h:outputLabel value="Logradouro: "/>
                                <p:row>
                                    <p:inputText value="#{managerBuscarImovel.objeto.logradouro}" size="49"/>
                                    <h:outputLabel value="Tipo: " for="tipo_logradouro" style="margin-left: 2%; width: 40px; float: none;"/>   
                                    <p:selectOneMenu id="tipo_logradouro" styleClass="tipoSearch"
                                                     value="#{managerBuscarImovel.objeto.tipo}"  
                                                     label="Tipo " >  
                                        <f:selectItem itemLabel="Selecione" value="#{null}"/>                   
                                        <f:selectItems value="#{managerPessoa.selectItemTipoEndereco()}"/>  
                                    </p:selectOneMenu>
                                </p:row>

                                <h:outputLabel value="Nº: " for="enderecoNumero"/>   
                                <p:row>
                                    <p:inputText value="#{managerBuscarImovel.objeto.numero}" id="enderecoNumero" />
                                    <h:outputText value="  " />
                                    <h:outputText value="Bairro: " for="enderecoBairro" />
                                    <p:inputText value="#{managerBuscarImovel.objeto.bairro}" id="enderecoBairro"  />
                                    <h:outputText value=" Cidade: " for="cidade"/>
                                    <p:autoComplete id="cidadeEstado" value="#{managerBuscarImovel.objeto.cidade}" 
                                                    completeMethod="#{managerEndereco.completeCidade}"   
                                                    var="cidadeEstado" 
                                                    itemLabel="#{cidadeEstado.nom_cidade.concat(' - ')}#{cidadeEstado.cod_estado.nom_estado}"
                                                    itemValue="#{cidadeEstado}" converter="cidadeConverter" 
                                                    forceSelection="true"  converterMessage="Erro, verifique a cidade" 
                                                    minQueryLength="3" maxResults="10" dropdown="true"> 
                                        <p:ajax event="itemSelect" listener="#{managerBuscarImovel.handleSelectCidade}" />  
                                    </p:autoComplete>

                                </p:row>


                            </h:panelGrid>
                        </fieldset>

                        <br/>

                        <fieldset class="ui-fieldset" >
                            <legend><h:outputLabel value="Adquirente ou Transmitente"/></legend>
                            <h:panelGrid columns="2" id="panelGridEscolha"   style="width: 39%"
                                         styleClass="textAlignRight" columnClasses="textAlignRight">
                                <h:outputLabel value="Buscar por: "/>
                                <p:selectOneRadio id="options" value="#{managerBuscarImovel.opc}">  
                                    <f:selectItem itemLabel="Adquirente" itemValue="#{true}" />  
                                    <f:selectItem itemLabel="Transmitente" itemValue="#{false}" />  
                                            <p:ajax event="change" update="ATanterior"/>
                                </p:selectOneRadio> 
                            </h:panelGrid>
                            <h:panelGrid columns="2" id="panelGridAdquirente"  style="width: 100%"
                                         styleClass="textAlignRight"
                                         columnClasses="textAlignRight">

                                <h:outputLabel value="Nome: "/>
                                <p:inputText value="#{managerBuscarImovel.pessoaBuscar.nome}"
                                             id="nome_pessoa" size="51" />


                                <h:outputLabel value="CPF: "/>  
                                <p:row>
                                    <p:inputMask value="#{managerBuscarImovel.pessoaBuscar.cpf}" 
                                                 id="cpf_pessoa" mask="999.999.999-99"   maxlength="11" style="width: 175px"/>

                                    <h:outputLabel value="CNPJ: " style="margin-left: 2%; width: 40px; float: none;"/>    
                                    <p:inputMask value="#{managerBuscarImovel.pessoaBuscar.cnpj}" 
                                                 id="cnpj_pessoa" mask="99.999.999/9999-99" maxlength="14" style="width: 178px"/>
                                </p:row>

                                <h:outputLabel value=" "/>  
                                <p:row>
                                    <p:column>
                                        <p:selectBooleanCheckbox  value="#{managerBuscarImovel.ATanterior}" />
                                    </p:column>
                                    <p:column>
                                        <h:outputText id="ATanterior" 
                                                      value="#{managerBuscarImovel.opc ? 'Adquirente' : 'Transmitente'} Anterior"/>
                                    </p:column>
                                </p:row> 

                            </h:panelGrid>
                        </fieldset>

                    </fieldset> 
                </f:validateBean>

                    <div class="buttonAction">
                        <p:commandButton id="buscarCommandButton" icon="ui-icon-search" value="Buscar" 
                                         actionListener="#{managerBuscarImovel.buscarImovel()}" process="@form" update="@form, imovelTable2"/>
                        <p:commandButton id="limparCommandButton" icon="ui-icon-close" value="Limpar"
                                         actionListener="#{managerBuscarImovel.init()}" update="@form"/>  

                    </div>
                    <center>
                        <p:ajaxStatus style="width:16px;height:16px;" id="carregandoBuscar">  
                            <f:facet name="start">  
                                <h:graphicImage value="/media/img/loading.gif" />  
                            </f:facet>  
                            <f:facet name="complete">  
                                <h:outputText value="" /> 
                            </f:facet>  
                        </p:ajaxStatus>
                    </center>

                    <fieldset class="ui-fieldset" >
                        <legend><h:outputLabel value="Resultado"/></legend>
                        <h:panelGrid columns="2" id="panelGridResult2" styleClass="textAlignRight" columnClasses="textAlignRight" width="945">

                            <p:dataTable id="imovelTable2" var="imovels" 
                                         value="#{managerBuscarImovel.lstTransf}" emptyMessage="Nenhum registro encontrado" 
                                         paginator="true" rows="5"
                                         paginatorPosition="bottom"
                                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "  
                                         rowsPerPageTemplate="5,10,15"
                                         draggableColumns="true"

                                         rowKey="#{imovels.id}"
                                         selectionMode="single"
                                         >  
                                <f:facet name="header">  
                                    Imovéis Cadastrados
                                </f:facet>

                                <p:column style="width:16px">  
                                    <p:rowToggler />  
                                </p:column>
                                <p:column style="width:90px;">  
                                    <f:facet name="header" >   
                                        Registro   
                                    </f:facet>  
                                    <h:outputText value="#{imovels.imovel.registro}" />  
                                </p:column>
                                <p:column>  
                                    <f:facet name="header" >   
                                        Objeto 
                                    </f:facet>  
                                    <h:outputText value="#{imovels.imovel.objeto.tipo}" escape="false" />  
                                </p:column>
                                <p:column>  
                                    <f:facet name="header" >   
                                        Adquirente
                                    </f:facet>  
                                    <ui:repeat value="#{imovels.adquirente}" var="ad" >
                                        -<p:commandLink  actionListener="#{managerVisualizarPessoa.redirect('visualizarPessoa.xhtml',ad)}" value="#{ad.nome}" />
                                        <br/>
                                    </ui:repeat>
                                </p:column>
                                <p:column>  
                                    <f:facet name="header" >   
                                        Transmitente    
                                    </f:facet>  
                                    <ui:repeat value="#{imovels.transmitente}" var="tra" >
                                        -<p:commandLink  actionListener="#{managerVisualizarPessoa.redirect('visualizarPessoa.xhtml',tra)}" value="#{tra.nome}" />
                                        <br/>
                                    </ui:repeat>
                                </p:column>
                                <p:rowExpansion >  
                                    <h:outputText value="Descrição do Objeto: " style="font-weight:bold;" />  
                                    <h:outputText value="Um(a) #{imovels.imovel.objeto.tipo} localizada(o) na #{imovels.imovel.objeto.tipo_logradouro} 
                                                  #{imovels.imovel.objeto.logradouro}, #{imovels.imovel.objeto.numero}, bairro #{imovels.imovel.objeto.bairro}; com as
                                                  seguintes confrontações: frente, #{imovels.imovel.objeto.frente}, lado direito, #{imovels.imovel.objeto.ladoDireito}, lado esquerdo,
                                                  #{imovels.imovel.objeto.ladoEsquerdo}
                                                  " escape="true" />   
                                    <br/>
                                </p:rowExpansion> 
                                <p:column style="width:120px;" headerText="Opções">  
                                    <p:commandButton style="float:left;" title="Transferir Imóvel" icon="transferir" actionListener="#{managerTransfencia.transferirImovel(imovels.imovel)}" update="@form"/>
                                    <p:commandButton style="float:left;" title="Averbar Imóvel" icon="averbar" actionListener="#{managerAverbacao.averbarImovel(imovels.imovel)}" update="@form"/>
                                    <p:commandButton style="float:left;" title="Registrar Imóvel" icon="registro" actionListener="#{managerRegistro.registrarImovel(imovels.imovel)}" update="@form"/>
                                    <p:commandButton style="float:left;" title="Visualizar Imóvel" icon="view" actionListener="#{managerBuscarImovel.verImovel(imovels.imovel)}" update="@form"/>
                                </p:column>    
                            </p:dataTable>
                            <p:blockUI block="imovelTable2" trigger="imovelTable2">  
                                CARREGANDO...<br />  
                                <p:graphicImage value="/media/img/ajax-loader.gif"/>  
                            </p:blockUI>

                        </h:panelGrid>
                    </fieldset>



                </p:panel>
                <br/>

            </h:form>
        </ui:define>
    </ui:composition>
</html>